// 判断二叉树的深度
// 闭包实现
function deep(tree) {
    let max = 0
    function fn(node, d) {
        if (node === null) {
            max = Math.max(max, d)
        } else {
            fn(node.left, d + 1)
            fn(node.right, d + 1)
        }
    }
    fn(tree, 0)
    return max
}

// 递归实现
function deep(tree) {
    return tree === null
        ? 0
        : Math.max(deep(tree.left), deep(tree.right)) + 1
}


// test
const tree = {
    value: 0,
    left: {
        value: 1,
        left: {
            value: 2,
            left: {
                value: 3,
                left: null,
                right: null
            },
            right: null
        },
        right: null
    },
    right: {
        value: 1,
        left: null,
        right: {
            value: 2,
            left: null,
            right: null
        }
    }
}
console.log(deep(tree))
